//
//  MainTabBarCon.m
//  Item
//
//  Created by 刘炳举 on 12/15/15.
//  Copyright © 2015 Kelly. All rights reserved.
//

#import "MainTabBarCon.h"
#import "ViewController.h"
@interface MainTabBarCon ()
@end

@implementation MainTabBarCon

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self initTitleBar];
    self.navigationController.navigationBarHidden = YES;//两个都注释：返回首页时返回按钮加载完后才消失
    [self.navigationItem setHidesBackButton:YES];
    self.navigationController.navigationBarHidden = NO;//注释的话在注册界面返回按钮消失
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.navigationItem setHidesBackButton:YES animated:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    [self.navigationItem setTitle:@"交易"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initTitleBar {
   UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
                                initWithTitle:@"返回"
                                style:UIBarButtonItemStylePlain
                                target:self
                                action:nil];
    self.navigationController.navigationBar.topItem.backBarButtonItem=btnBack;
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    NSInteger selectedIndex = [tabBarController.viewControllers indexOfObject:viewController];
    if (selectedIndex == 0) {
        [self initTitleBar];
        [self.navigationItem setTitle:@"交易"];
    } else if (selectedIndex == 1) {
        [self initTitleBar];
        [self.navigationItem setTitle:@"查询"];
    }else if (selectedIndex == 2) {
        [self initTitleBar];
        [self.navigationItem setTitle:@"设置"];
    }
    return YES;
    
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//    if ((int)self.selectedIndex == 2) {
//        //    }
}

@end
